package com.novellotus.iov.carvice.activity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.utils.MyUtils;
import com.novellotus.iov.carvice.utils.WaveHelper;
import com.novellotus.iov.carvice.view.WaveView;

import butterknife.BindView;
import butterknife.OnClick;

public class ChargeDetailActivity extends BaseActivity {

    @BindView(R.id.tv_tittle)
    TextView tv_tittle;
    @BindView(R.id.wave)
    WaveView wave;
    @BindView(R.id.btn_charge)
    Button btn_charge;
    WaveHelper mWaveHelper;
    boolean isCharge;

    @Override
    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_charge_detail);
    }

    @Override
    public void init() {
        tv_tittle.setText("充电");
        mWaveHelper = new WaveHelper(wave);
        wave.setBorder((int) getResources().getDimension(R.dimen.wave_border_width), getResources().getColor(R.color.white));
        mWaveHelper.setPercent(65);
        mWaveHelper.setCharge(isCharge);
        mWaveHelper.startAnimation();
    }

    @OnClick(R.id.img_back)
    void back() {
        MyUtils.clearActivity();
        finish();
    }

    @OnClick(R.id.btn_charge)
    void clickCharge() {
        isCharge = !isCharge;
        mWaveHelper.setCharge(isCharge);
        if (isCharge) {
            mWaveHelper.cancel();
            btn_charge.setText("结束充电");
            btn_charge.setBackgroundResource(R.drawable.shape_btn_orange);
        } else {
            MyUtils.addActivity(this);
            openActivity(FirmOrderActivity.class);
            btn_charge.setText("开始充电");
            btn_charge.setBackgroundResource(R.drawable.shape_btn_green);
            mWaveHelper.startAnimation();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mWaveHelper != null) {
            mWaveHelper.cancel();
            mWaveHelper = null;
        }
    }
}
